from bisect import bisect_right
from typing import List


class Solution:
    #字符串处理 频率统计
    def f(self,s):
        c = min(s)
        return s.count(c)

    def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]:
        q = [self.f(s) for s in queries]
        w = [self.f(s) for s in words]
        w.sort()
        #核心
        ans = [len(w)-bisect_right(w,i) for i in q]
        return ans







